﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema
  targetNamespace="Sherwood.Content.UpdateScheduler"
  xmlns="Sherwood.Content.UpdateScheduler"
  attributeFormDefault="unqualified"
  elementFormDefault="qualified"
  xmlns:mstns="Sherwood.Content.UpdateScheduler"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="configuration" type="updateSchedulerConfiguration" />

  <xs:complexType name="client">
    <xs:sequence>
      <xs:element name="privateKey" type="xs:string" />
      <xs:element name="configuration">
        <xs:complexType>
          <xs:sequence>
            <xs:any minOccurs="0" maxOccurs="unbounded" processContents="skip" />
          </xs:sequence>
          <xs:anyAttribute processContents="skip" />
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="id" type="xs:string" use="required" />
    <xs:attribute name="lastSync" type="xs:dateTime" use="required" />
    <xs:attribute name="sourceType" type="xs:string" use="required" />
    <xs:attribute name="batchSize" type="xs:int" use="optional" />
  </xs:complexType>

  <xs:complexType name="jobSchedule">
    <xs:attribute name="client" type="xs:string" use="required" />
    <xs:attribute name="mode" use="required">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="Full" />
          <xs:enumeration value="Incremental" />
          <xs:enumeration value="PullDeletions" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="at" type="xs:dateTime" use="required" />
    <xs:attribute name="inactive" use="optional" type="xs:boolean" />
    <xs:attribute name="repeatEvery" use="optional">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:pattern value="^\s*-?(\d{0,7}|10[0-5]\d{0,5}|106[0-6]\d{0,4}|1067[0-4]\d{0,3}|10675[0-1]\d{0,2}|((\d{0,7}|10[0-5]\d{0,5}|106[0-6]\d{0,4}|1067[0-4]\d{0,3}|10675[0-1]\d{0,2})\.)?([0-1]?[0-9]|2[0-3]):[0-5]?[0-9](:[0-5]?[0-9](\.\d{1,7})?)?)\s*$" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:complexType>

  <xs:complexType name="updateSchedulerConfiguration">
    <xs:sequence>
      <xs:element name="clients">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="client" type="client" minOccurs="0" maxOccurs="unbounded" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="schedule">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="run" type="jobSchedule" minOccurs="0" maxOccurs="unbounded" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>